package firehwak.thoth.client.location;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MarkerLayer extends ItemizedOverlay<OverlayItem> {
	private final Context context;
	private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();

	public MarkerLayer(Drawable defaultMaker, Context c) {
		super(boundCenterBottom(defaultMaker));
		context = c;
		populate();
	}

	public void addOverlayItem(OverlayItem overlay) {
		overlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return overlays.get(i);
	}

	@Override
	public int size() {
		return overlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem overlayItem = overlays.get(index);

		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(overlayItem.getTitle());
		dialog.setMessage(overlayItem.getSnippet());
		dialog.setPositiveButton("Ok", new OnClickListener() {
			public void onClick(DialogInterface dialog, int wichButton) {
				dialog.cancel();
			}
		});
		dialog.show();

		return super.onTap(index);
	}
}
